home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / proteng.zip / ANSI_DRV.PAS < prev    next >
Pascal/Delphi Source File  |  1992-05-02  |  8KB  |  302 lines

  1.  
  2.  
  3. {Ansi Driver                                                              }
  4. {                                                                         }
  5. {    Copywrite 1990 Mark Dignam - OmenTronics - Perth Omen BBS.           }
  6. {    This program ,including the source code MAY not be modified, changed }
  7. {    or altered in any way without written permission of the author.      }
  8. {                                                                         }
  9.  
  10. unit Ansi_Drv;
  11.  
  12. interface
  13.  
  14.  
  15. Uses Crt,dos;
  16.  
  17.  
  18. procedure Ansi_Write(ch : char);
  19.  
  20. Implementation
  21.  
  22.  
  23. Var
  24.     Escape,Saved_X,
  25.     Saved_Y               : Byte;
  26.     Control_Code          : String;
  27.  
  28. function GetNumber(var Line:string):integer;
  29.  
  30.    var
  31.      i,j,k         : integer;
  32.      temp0,temp1   : String;
  33.  
  34.   Begin
  35.        temp0 := line;
  36.        val(temp0,i,j);
  37.       if j = 0 then temp0 :=''
  38.        else
  39.       begin
  40.          temp1:= copy(temp0,1,j-1);
  41.          delete(temp0,1,j);
  42.          val(temp1,i,j);
  43.       end;
  44.     line := temp0;
  45.     GetNumber := i;
  46.   end;
  47.  
  48.  procedure loseit;
  49.     begin
  50.       escape := 0;
  51.       control_code := '';
  52.     end;
  53.  
  54.  procedure Ansi_Cursor_move;
  55.  
  56.      var
  57.       x,y       : integer;
  58.  
  59.     begin
  60.      y := GetNumber(control_code);
  61.      if y = 0 then y := 1;
  62.      x := GetNumber(control_code);
  63.      if x = 0 then x := 1;
  64.      if y > 25 then y := 25;
  65.      if x > 80 then x := 80;
  66.      gotoxy(x,y);
  67.     loseit;
  68.     end;
  69.  
  70. procedure Ansi_Cursor_up;
  71.  
  72.  Var
  73.    y,new_y,offset          : integer;
  74.  
  75.    Begin
  76.      Offset := getnumber(control_code);
  77.         if Offset = 0 then offset := 1;
  78.       y := wherey;
  79.       if (y - Offset) < 1 then
  80.              New_y := 1
  81.           else
  82.              New_y := y - offset;
  83.        gotoxy(wherex,new_y);
  84.   loseit;
  85.   end;
  86.  
  87. procedure Ansi_Cursor_Down;
  88.  
  89.  Var
  90.    y,new_y,offset          : integer;
  91.  
  92.    Begin
  93.      Offset := getnumber(control_code);
  94.         if Offset = 0 then offset := 1;
  95.       y := wherey;
  96.       if (y + Offset) > 25 then
  97.              New_y := 25
  98.           else
  99.              New_y := y + offset;
  100.        gotoxy(wherex,new_y);
  101.   loseit;
  102.   end;
  103.  
  104. procedure Ansi_Cursor_Left;
  105.  
  106.  Var
  107.    x,new_x,offset          : integer;
  108.  
  109.    Begin
  110.      Offset := getnumber(control_code);
  111.         if Offset = 0 then offset := 1;
  112.       x := wherex;
  113.       if (x - Offset) < 1 then
  114.              New_x := 1
  115.           else
  116.              New_x := x - offset;
  117.        gotoxy(new_x,wherey);
  118.   loseit;
  119.   end;
  120.  
  121. procedure Ansi_Cursor_Right;
  122.  
  123.  Var
  124.    x,new_x,offset          : integer;
  125.  
  126.    Begin
  127.      Offset := getnumber(control_code);
  128.         if Offset = 0 then offset := 1;
  129.       x := wherex;
  130.       if (x + Offset) > 80 then
  131.              New_x := 1
  132.           else
  133.              New_x := x + offset;
  134.        gotoxy(New_x,wherey);
  135.   loseit;
  136.   end;
  137.  
  138.  procedure Ansi_Clear_Screen;
  139.  
  140.    begin                         {   0J = cusor to Eos           }
  141.      Clrscr;                      {  1j start to cursor           }
  142.      loseit;                       { 2j entie screen/cursor no-move}
  143.    end;
  144.  
  145.  procedure Ansi_Clear_EoLine;
  146.  
  147.    begin
  148.      clreol;
  149.      loseit;
  150.    end;
  151.  
  152.  
  153.  procedure Reverse_Video;
  154.  
  155.  var
  156.       tempAttr,tblink,tempAttrlo,tempAttrhi : Byte;
  157.  
  158.  begin
  159.             LowVideo;
  160.             TempAttrlo := (TextAttr and $7);
  161.             tempAttrHi := (textAttr and $70);
  162.             tblink     := (textattr and $80);
  163.             tempattrlo := tempattrlo * 16;
  164.             tempattrhi := tempattrhi div 16;
  165.             TextAttr   := TempAttrhi+TempAttrLo+TBlink;
  166.   end;
  167.  
  168.  
  169.  procedure Ansi_Set_Colors;
  170.  
  171.  var
  172.     temp0,Color_Code   : integer;
  173.  
  174.     begin
  175.         if length(control_code) = 0 then control_code :='0';
  176.            while (length(control_code) > 0) do
  177.            begin
  178.             Color_code := getNumber(control_code);
  179.                 case Color_code of
  180.                    0          :  begin
  181.                                    LowVideo;
  182.                                    TextColor(LightGray);
  183.                                    TextBackground(Black);
  184.                                  end;
  185.                    1          : HighVideo;
  186.                    5          : TextAttr := (TextAttr or $80);
  187.                    7          : Reverse_Video;
  188.                    30         : textAttr := (TextAttr And $F8) + black;
  189.                    31         : textattr := (TextAttr And $f8) + red;
  190.                    32         : textattr := (TextAttr And $f8) + green;
  191.                    33         : textattr := (TextAttr And $f8) + brown;
  192.                    34         : textattr := (TextAttr And $f8) + blue;
  193.                    35         : textattr := (TextAttr And $f8) + magenta;
  194.                    36         : textattr := (TextAttr And $f8) + cyan;
  195.                    37         : textattr := (TextAttr And $f8) + Lightgray;
  196.                    40         : textbackground(black);
  197.                    41         : textbackground(red);
  198.                    42         : textbackground(green);
  199.                    43         : textbackground(yellow);
  200.                    44         : textbackground(blue);
  201.                    45         : textbackground(magenta);
  202.                    46         : textbackground(cyan);
  203.                    47         : textbackground(white);
  204.                  end;
  205.              end;
  206.        loseit;
  207.   end;
  208.  
  209.  
  210.  procedure Ansi_Save_Cur_pos;
  211.  
  212.     Begin
  213.       Saved_X := WhereX;
  214.       Saved_Y := WhereY;
  215.       loseit;
  216.     end;
  217.  
  218.  
  219.  procedure Ansi_Restore_cur_pos;
  220.  
  221.     Begin
  222.       GotoXY(Saved_X,Saved_Y);
  223.       loseit;
  224.     end;
  225.  
  226.  
  227.  procedure Ansi_check_code( ch : char);
  228.  
  229.    begin
  230.        case ch of
  231.             '0'..'9',';'     : control_code := control_code + ch;
  232.             'H','f'          : Ansi_Cursor_Move;
  233.             'A'              : Ansi_Cursor_up;
  234.             'B'              : Ansi_Cursor_Down;
  235.             'C'              : Ansi_Cursor_Right;
  236.             'D'              : Ansi_Cursor_Left;
  237.             'J'              : Ansi_Clear_Screen;
  238.             'K'              : Ansi_Clear_EoLine;
  239.             'm'              : Ansi_Set_Colors;
  240.             's'              : Ansi_Save_Cur_Pos;
  241.             'u'              : Ansi_Restore_Cur_pos;
  242.         else
  243.           loseit;
  244.         end;
  245.    end;
  246.  
  247.  
  248. procedure Ansi_Write(ch : char);
  249.  
  250. Var
  251.   temp0      : Integer;
  252.  
  253. begin
  254.        if escape > 0 then
  255.           begin
  256.               case Escape of
  257.                 1    : begin
  258.                          if ch = '[' then
  259.                             begin
  260.                               escape := 2;
  261.                               Control_Code := '';
  262.                             end
  263.                          else
  264.                              escape := 0;
  265.                        end;
  266.                 2    : Ansi_Check_code(ch);
  267.               else
  268.                 begin
  269.                    escape := 0;
  270.                    control_code := '';
  271.                 end;
  272.               end;
  273.           end
  274.        else
  275.          Begin
  276.           Case Ch of
  277.              #27       : Escape := 1;
  278.              #9        : Begin
  279.                             temp0:= wherex;
  280.                             temp0 := temp0 div 8;
  281.                             temp0 := temp0 + 1;
  282.                             temp0 := temp0 * 8;
  283.                             gotoxy(temp0,wherey);
  284.                          end;
  285.              #12       : ClrScr;
  286.           else
  287.                  begin
  288.                     if ((wherex = 80) and (wherey = 25)) then
  289.                       begin
  290.                         windmax := (80 + (24*256));
  291.                         write(ch);
  292.                         windmax := (79 + (24*256));
  293.                       end
  294.                     else
  295.                       write(ch);
  296.                     escape := 0;
  297.                  end;
  298.            end;
  299.          end;
  300.   End;
  301. end.
  302.